package com.huobao.yunying.adapters;

import java.util.Map;

import com.huobao.yunying.entity.SaveStore;
import com.huobao.yunying.https.Http;
import com.huobao.yunying.https.HttpListener;
import com.huobao.yunying.https.HttpUtil;
import com.huobao.yunying.utils.ImageUtils;
import com.huobao.zhangying.R;
import com.xrz.sxm.base.dialog.BaseDialog;

import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import joanzapata.android.BaseAdapterHelper;
import joanzapata.android.QuickAdapter;

public class Adapter_Save_Store extends QuickAdapter<SaveStore> {

	public Adapter_Save_Store(Context context) {
		super(context, R.layout.item_save_store);
	}

	@Override
	protected void convert(BaseAdapterHelper arg0, final SaveStore arg1) {
		arg0.setText(R.id.tv_name, "店名：" + arg1.store_name).setText(R.id.tv_price, "掌柜：" + arg1.owner_name)
				.setText(R.id.tv_time, "收藏时间：" + arg1.add_time);
		TextView tv_del = arg0.getView(R.id.tv_del);
		ImageView imageView = arg0.getView(R.id.imgView);
		ImageUtils.loadimg(imageView, arg1.store_logo);
		tv_del.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				BaseDialog.TBox("确定删除?", context, new BaseDialog.OnDialogSelectListener() {
					@Override
					public void onSelect(String input) {
						if(input.equals("true")){
							Map<String, String> map = HttpUtil.getParams("app", "member", "act", "drop_collect", "type", "store",
									"item_id", arg1.store_id);
							Http.getInstant().sendRequest(context, map, new HttpListener() {

								@Override
								public void onHttpSuccess(String result) {
									Toast.makeText(context, "删除成功", Toast.LENGTH_SHORT).show();
									getList().remove(arg1);
									notifyDataSetChanged();
								}

								@Override
								public void onHttpError(String error) {

								}
							});
						}
					}
				});

			}
		});
	}

}
